package com.java.mall_imooc.controller;

import com.java.mall_imooc.common.utils.PageUtils;
import com.java.mall_imooc.common.utils.R;
import com.java.mall_imooc.entity.OrderItem;
import com.java.mall_imooc.service.OrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;




/**
 * 订单明细表
 *
 * @author jl
 * @since 2020-03-14 23:41:10
 */
@RestController
@RequestMapping("account/orderitem")
public class OrderItemController {
    @Autowired
    private OrderItemService orderItemService;

    /**
     * 分页查询orderItem
     * 当前页码page、每页显示记录数limit
     */
    @GetMapping("/list")
    public R list(OrderItem orderItem, @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        if (pageNum < 1) pageNum = 1;
        if (pageSize > 100) pageSize = 100;
        PageUtils page = orderItemService.queryPage(orderItem, pageNum, pageSize);

        return R.ok(page);
    }


    /**
     * 根据主键查询orderItem
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		OrderItem orderItem = orderItemService.getById(id);

        return R.ok(orderItem);
    }

    /**
     * 新增orderItem
     */
    @PostMapping("/save")
    public R save(@RequestBody OrderItem orderItem){
		orderItemService.save(orderItem);

        return R.ok();
    }

    /**
     * 修改orderItem
     */
    @PutMapping("/update")
    public R update(@RequestBody OrderItem orderItem){
		orderItemService.updateById(orderItem);

        return R.ok();
    }

    /**
     * 删除orderItem
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		orderItemService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
